<template>
  <upload-execl :on-success="success" />
</template>

<script>
import { formatDate } from '@/utils/index'
import { importEmployee } from '@/api/employees'
export default {
  methods: {
    async success({ header, results }) {
      const chineseKey2English = {
        '入职日期': 'timeOfEntry',
        '姓名': 'username',
        '工号': 'workNumber',
        '手机号': 'mobile',
        '转正日期': 'correctionTime'
      }
      const data = results.map(item => {
        const tempObj = {}
        for (const key in item) {
          const k = chineseKey2English[key]
          console.log(k)
          if (k === 'timeOfEntry' || k === 'correctionTime') {
            tempObj[k] = formatDate(item[key], '-')
          } else {
            tempObj[k] = item[key]
          }
        }
        return tempObj
      })
      console.log(data)
      const res = await importEmployee(data)
      if (res.success) {
        this.$message({
          type: 'success',
          message: '导入成功!'
        })
      }
    }
  }
}

</script>

<style>

</style>
